package com.cy.common.entity;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author : 残影
 * @Date: 2022/4/12
 */
public class Result extends HashMap<String, Object> {
    public Result() {
        put("code", 200);
    }

    public static Result failed() {
        return failed(500, "未知异常，请联系管理员");
    }

    public static Result failed(String msg) {
        return failed(500, msg);
    }

    public static Result failed(int code, String msg) {
        Result r = new Result();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    public static Result ok(String msg) {
        Result r = new Result();
        r.put("msg", msg);
        return r;
    }

    public static Result ok(String msg, Object obj) {
        Result r = new Result();
        r.put("msg", msg);
        r.put("data", obj);
        return r;
    }

    public static Result ok(String msg, Map<String, Object> map) {
        Result r = new Result();
        r.put("msg", msg);
        r.put("data", map);
        return r;
    }

    public static Result ok(Map<String, Object> map) {
        Result r = new Result();
        r.putAll(map);
        return r;
    }

    public static Result ok() {
        return new Result();
    }

    @Override
    public Result put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
